** Replication materials for "Female Officeholders and Women's Political Engagement: The Role of Parties"
** Analyses of role model effects on mass public
** Author: Oscar Castorena
** Data: Mexico 2012 Panel downloaded from ICPSR repository
**		 (https://doi.org/10.3886/ICPSR35024.v1)
** 		 & district-level electoral results compiled by author
**		 (mx_leg_election.dta)
** Tables replicated with this do file: Tables A1, A2, A3, A4, A5
** Figures replicated with this do file: 2, 3, A1, A2, A3


** Make sure to install estout, coefplot, and combomarginsplot

* File path of data here
cd "C:\Users\castoro\Documents\"

* set font for figures
graph set window fontface TrebuchetMS

* read panel data downloaded from ICPSR
use "MexPanel2012.dta", clear

** Data Management **
gen distrito = PX3
gen cve_ent = PX6
gen district_id = cve_ent * 100 + distrito
gen seccion = PX2C

* merge election data
merge m:1 district_id using "mx_leg_election_data.dta"
drop if _merge == 2 | _merge == 1
drop _merge

gen sexo = P1
gen mujer = 1 if P1 == 2
replace mujer = 0 if P1 == 1
label variable mujer "Woman"

gen age = P2
gen age_group = 1 if inlist(P2, 1, 2, 3)
replace age_group = 2 if inlist(P2, 4, 5, 6, 7)
replace age_group = 3 if inlist(P2, 8, 9, 10, 11, 12)
label define agegroup_eng 1 "Age 30 and under" 2 "Age 31 - 50" 3 "Age 51+"
label values age_group agegroup_eng
tabulate age_group, gen(age_group_indicator)

gen edu = 1 if P44 == 1 | P44 == 2
replace edu = 2 if P44 == 3
replace edu = 3 if P44 == 4
replace edu = 4 if P44 == 5
replace edu = 5 if P44 == 6
replace edu = 6 if P44 == 7
replace edu = 7 if inlist(P44, 8, 9)

gen edr = 1 if inlist(edu, 1, 2)
replace edr = 2 if inlist(edu, 3, 4)
replace edr = 3 if inlist(edu, 5, 6)
replace edr = 4 if edu == 7
label define edr_eng 1 "None or Primary Ed." 2 "Secondary Ed." 3 "Preparatory Ed." 4 "University" 
label values edr edr_eng
tabulate edr, gen(edr_indicator)

gen religion = 1 if P41 == 1
replace religion = 2 if inlist(P41, 2, 3)
replace religion = 3 if P41 == 4
replace religion = 4 if P41 == 5

gen household_income = P49
recode household_income (9=.)(4=0)(3=1)(2=2)(1=3)
replace household_income = household_income / 3
lab var household_income "Household Income"

gen votepres = 1 if W2_P8 == 1
replace votepres = 2 if inlist(W2_P8, 2, 4, 9)
replace votepres = 3 if inlist(W2_P8, 3, 5, 6, 10)
replace votepres = 4 if W2_P8 == 7
replace votepres = 8 if inlist(W2_P8, 8, 11, 12)
replace votepres = 9 if inlist(W2_P8, 13, 99)

* pol interest
gen pol_int_W2 = W2_P5
replace pol_int_W2 = . if pol_int_W2 == 9
recode pol_int_W2 (4=0)(3=1)(2=2)(1=3)
replace pol_int_W2 = pol_int_W2 / 3
label variable pol_int_W2 "Political Interest"

gen pol_int_W1 = P5
replace pol_int_W1 = . if pol_int_W1 == 9
recode pol_int_W1 (4=0)(3=1)(2=2)(1=3)
replace pol_int_W1 = pol_int_W1 / 3
label variable pol_int_W1 "Political Interest (t-1)"

gen change_pol_int = pol_int_W2 - pol_int_W1

* talk about politics
gen pol_talk_W2 = W2_P6
recode pol_talk_W2 (9=.)(5=0)(4=1)(3=2)(2=3)(1=4)
replace pol_talk_W2 = pol_talk_W2 / 4
lab var pol_talk_W2 "Political Discussion"

* political information
gen p33a_recode = P33A
recode p33a_recode (5 9=.)
recode P33A (1=4)(2=3)(3=2)(4=1)(5 9=.), gen(tv_news)
lab var tv_news "Political News Consumption (t-1)"
*replace tv_news = (tv_news - 1)/3

* W1 PID
gen panista = 1 if inlist(P22, 1, 2)
replace panista = 1 if inlist(P23, 1)
replace panista = 0 if panista == .
gen panista_s = 2 if inlist(P22, 1)
replace panista_s = 1 if inlist(P22, 2)
replace panista_s = 1 if inlist(P23, 1)
replace panista_s = 0 if panista_s == .

gen priista = 1 if inlist(P22, 3, 4)
replace priista = 1 if inlist(P23, 2)
replace priista = 0 if priista == .
gen priista_s = 2 if inlist(P22, 3)
replace priista_s = 1 if inlist(P22, 4)
replace priista_s = 1 if inlist(P23, 2)
replace priista_s = 0 if priista_s == .

gen prdista = 1 if inlist(P22, 5, 6)
replace prdista = 1 if inlist(P23, 3)
replace prdista = 0 if prdista == .
gen prdista_s = 2 if inlist(P22, 5)
replace prdista_s = 1 if inlist(P22, 6)
replace prdista_s = 1 if inlist(P23, 3)
replace prdista_s = 0 if prdista_s == .

* W1 pres vote preference
gen jvm_w1 = 1 if P8 == 1
replace jvm_w1 = 0 if P8 != 1 & P8 != .
label variable jvm_w1 "JVM vote intention (t-1)"
gen epn_w1 = 1 if inlist(P8, 2, 4, 9)
replace epn_w1 = 0 if !inlist(P8, 2, 4, 9) & P8 != .
label variable epn_w1 "EPN vote intention (t-1)"
gen amlo_w1 = 1 if inlist(P8, 3, 5, 6, 10)
replace amlo_w1 = 0 if !inlist(P8, 3, 5, 6, 10) & P8 != .
label variable amlo_w1 "AMLO vote intention (t-1)"
gen otherAbstain_w1 = 1 if inlist(P8, 7, 8, 11, 12, 13, 99)
replace otherAbstain_w1 = 0 if !inlist(P8, 7, 8, 11, 12, 13, 99) & P8 != .

* woman SMD winner 
gen woman_legwin = 1 if winner_gender_12 == "M"
replace woman_legwin = 0 if winner_gender_12 == "H"
label variable woman_legwin "Woman district winner"
gen woman_legwin_prev = 1 if winner_gender_09 == "M"
replace woman_legwin_prev = 0 if winner_gender_09 == "H"
* co-partisan with winner
gen copartisan = 1 if panista == 1 & first_12 == "PAN"
replace copartisan = 1 if prdista == 1 & first_12 == "PRD COALITION"
replace copartisan = 1 if priista == 1 & first_12 == "PRI"
replace copartisan = 1 if priista == 1 & first_12 == "PRI-PVEM"
replace copartisan = 1 if priista == 1 & first_12 == "PVEM"
replace copartisan = 0 if copartisan == .
lab var copartisan "Copartisanship with Winner(t-1)"
* with strength
gen copartisan_s = panista_s if panista == 1 & first_12 == "PAN"
replace copartisan_s = prdista_s if prdista == 1 & first_12 == "PRD COALITION"
replace copartisan_s = priista_s if priista == 1 & first_12 == "PRI"
replace copartisan_s = priista_s if priista == 1 & first_12 == "PRI-PVEM"
replace copartisan_s = priista_s if priista == 1 & first_12 == "PVEM"
replace copartisan_s = 0 if copartisan_s == .
lab var copartisan_s "Copartisanship with Winner (t-1)"
lab define coparty 0 "Not Copartisan" 1 "Weak Copartisan" 2 "Strong Copartisan"
lab values copartisan_s coparty


** Data Analysis **

** Pooled analyses
eststo clear
* pooled analysis (political interest)
eststo: reg pol_int_W2 pol_int_W1 i.mujer##i.woman_legwin jvm_w1 epn_w1 amlo_w1 i.age_group i.edr household_income, robust
margins, dydx(woman_legwin) at(mujer=(0(1)1))
marginsplot, scheme(s2mono) recast(scatter) xscale(range(-.3 1.3)) graphregion(color(white)) title(Political Interest) ///
ytitle("Effect of Woman Winning District") yline(0, lpattern(dash)) xtitle("Gender") xlabel(0 "Man" 1 "Woman") saving(pol_int_pool, replace)
* pooled analysis (political discussion)
eststo: reg pol_talk_W2 pol_int_W1 i.mujer##i.woman_legwin jvm_w1 epn_w1 amlo_w1 i.age_group i.edr household_income, robust
margins, dydx(woman_legwin) at(mujer=(0(1)1))
marginsplot, scheme(s2mono) recast(scatter) xscale(range(-.3 1.3)) graphregion(color(white)) title(Political Discussion) ///
ytitle("") yline(0, lpattern(dash)) xtitle("Gender") xlabel(0 "Man" 1 "Woman") saving(pol_talk_pool, replace)
* plot of interaction effects (Fig. A1)
graph combine pol_int_pool.gph pol_talk_pool.gph, row(1) scheme(s1mono) ycommon
graph export panelLDV_pooled.pdf, replace
* latex reg table for pooled analyses (Table A2)
esttab using pol_intW2_pooled.tex, replace star(+ 0.10 * 0.05) se r2 label nobaselevels varwidth(25) mtitles("Interest" "Discussion") ///
title("OLS Models of Post-Election Political Engagement: Pooled with Gender-Woman Winner Interaction"\label{tab:panelSurveyResultsPooled})

** Split sample analysis
eststo clear
* political interest
eststo w_int: reg pol_int_W2 pol_int_W1 woman_legwin jvm_w1 epn_w1 amlo_w1 i.age_group i.edr household_income if sexo == 2, robust
eststo m_int: reg pol_int_W2 pol_int_W1 woman_legwin jvm_w1 epn_w1 amlo_w1 i.age_group i.edr household_income if sexo == 1, robust
* political discussion
eststo w_talk: reg pol_talk_W2 pol_int_W1 woman_legwin jvm_w1 epn_w1 amlo_w1 i.age_group i.edr household_income if sexo == 2, robust
eststo m_talk: reg pol_talk_W2 pol_int_W1 woman_legwin jvm_w1 epn_w1 amlo_w1 i.age_group i.edr household_income if sexo == 1, robust
* coefficient plot (Fig. 2)
coefplot (w_int, label(Women) msymbol(cricle)) (m_int, label(Men) msymbol(square)), bylabel(Political Interest) ///
|| (w_talk, label(Women) msymbol(cricle)) (m_talk, label(Men) msymbol(square)), bylabel(Political Discussion) ///
||, drop(_cons) xline(0) scheme(plotplain) byopts(xrescale) legend(row(1)) levels(95 90) scale(1.5)
*caption("Source: Mexico Panel Study, 2012. Notes: Points represent coefficients for models of post-election political" "interest. Thick lines indicate 90% confidence interval. Thin lines indicate 95% confidence interval. Coefficient" "of interest denoted with asterisk.", span size(small)) 
graph export panelLDV.pdf, replace
* latex reg table (Table A1)
esttab using pol_intW2.tex, replace star(+ 0.10 * 0.05) se r2 label nobaselevels varwidth(25) mtitles("\shortstack{Interest\\Women}" "\shortstack{Interest\\Men}" "\shortstack{Discussion\\Women}" "\shortstack{Discussion\\Men}") ///
title("OLS Models of Post-Election Political Engagement"\label{tab:panelSurveyResults})


** Heterogeneous effects by copartisanship
eststo clear
* women
eststo: reg pol_int_W2 pol_int_W1 i.age_group i.edr household_income i.copartisan_s##i.woman_legwin if sexo == 2, robust
margins, dydx(woman_legwin) at(copartisan_s=(0(1)2)) saving(coparty_w95, replace) level(95)
margins, dydx(woman_legwin) at(copartisan_s=(0(1)2)) saving(coparty_w90, replace) level(90)
combomarginsplot coparty_w95 coparty_w90, scheme(plotplain) recast(scatter) yline(0) ///
file1opts(msymbol(circle) mcolor(gs6)) file2opts(msymbol(circle) mcolor(gs6)) ///
fileci1opts(recast(rspike) lwidth(medium) lcolor(gs6)) fileci2opts(recast(rspike) lwidth(thick) lcolor(gs6)) ///
xtitle("Copartisanship with District Winner") xscale(range(0 2.1)) legend(off) scale(1.2) ///
xlabel(0 `" "Not"  "copartisan" "' 1 `" "Weak"  "copartisan" "' 2 `" "Strong"  "copartisan" "') ///
ytitle("Effect of Woman Winning District") title("Women", size(medlarge)) saving(coparty_w, replace)
* men
eststo: reg pol_int_W2 pol_int_W1 i.age_group i.edr household_income i.copartisan_s##i.woman_legwin if sexo == 1, robust
margins, dydx(woman_legwin) at(copartisan_s=(0(1)2)) saving(coparty_m95, replace) level(95)
margins, dydx(woman_legwin) at(copartisan_s=(0(1)2)) saving(coparty_m90, replace) level(90)
combomarginsplot coparty_m95 coparty_m90, scheme(plotplain) recast(scatter) yline(0) ///
file1opts(msymbol(circle) mcolor(gs6)) file2opts(msymbol(circle) mcolor(gs6)) ///
fileci1opts(recast(rspike) lwidth(medium) lcolor(gs6)) fileci2opts(recast(rspike) lwidth(thick) lcolor(gs6)) ///
xtitle("Copartisanship with District Winner") xscale(range(0 2.1)) legend(off) scale(1.2) ///
xlabel(0 `" "Not"  "copartisan" "' 1 `" "Weak"  "copartisan" "' 2 `" "Strong"  "copartisan" "') ///
ytitle("Effect of Woman Winning District") title("Men", size(medlarge)) saving(coparty_m, replace)
* plot of interaction effects (Fig. A3)
graph combine coparty_w.gph coparty_m.gph, row(1) ycommon scheme(plotplain) ///
note("Source: Mexico Panel Study, 2012. Notes: Thick lines indicate 90% confidence interval." ///
"Thin lines indicate 95% confidence interval.", span size(small)) 
graph export panelLDV_coparty.pdf, replace
* latex reg table (Table A4)
esttab using pol_int_coparty.tex, replace star(+ 0.10 * 0.05) compress se r2 label nobaselevels varwidth(25) mtitles("Women" "Men") ///
title("OLS Models of Post-Election Political Interest: Interactive Effect of Copartisanship with District Winner"\label{tab:panelSurveyResultsCoparty})


** Heterogenous effects by political information (pol. news consumption)
eststo clear
* women
eststo: reg pol_int_W2 pol_int_W1 c.tv_news##i.woman_legwin jvm_w1 epn_w1 amlo_w1 i.age_group i.edr household_income if sexo == 2, robust
margins, dydx(woman_legwin) at(tv_news=(1(1)4)) saving(pol_info_w95, replace) level(95)
margins, dydx(woman_legwin) at(tv_news=(1(1)4)) saving(pol_info_w90, replace) level(90)
* men
eststo: reg pol_int_W2 pol_int_W1 c.tv_news##i.woman_legwin jvm_w1 epn_w1 amlo_w1 i.age_group i.edr household_income if sexo == 1, robust
margins, dydx(woman_legwin) at(tv_news=(1(1)4)) saving(pol_info_m95, replace) level(95)
margins, dydx(woman_legwin) at(tv_news=(1(1)4)) saving(pol_info_m90, replace) level(90)
* plot of interaction effects for female respondents (Fig. 3)
combomarginsplot pol_info_w95 pol_info_w90, scheme(plotplain) recast(scatter) yline(0) ///
file1opts(msymbol(circle) mcolor(gs6)) file2opts(msymbol(circle) mcolor(gs6)) ///
fileci1opts(recast(rspike) lwidth(medium) lcolor(gs6)) fileci2opts(recast(rspike) lwidth(thick) lcolor(gs6)) ///
legend(off) xtitle("Political News Consumption (TV)") ytitle("Effect of Woman Winning District") title("") scale(1.2) ///
xlabel(1 `" "Every once"  "in a while" "' 2 `" "Once"  "a week" "' 3 `" "Several times"  "a week" "' 4 "Daily") ///
note("Source: Mexico Panel Study, 2012. Notes: Thick lines indicate 90% confidence interval." ///
"Thin lines indicate 95% confidence interval.", span size(small)) 
graph export panel_polinfo_women.pdf, replace
* plot of interaction effects for male respondents (Fig. A2)
combomarginsplot pol_info_m95 pol_info_m90, scheme(plotplain) recast(scatter) yline(0) ///
file1opts(msymbol(circle) mcolor(gs10)) file2opts(msymbol(circle) mcolor(gs10)) ///
fileci1opts(recast(rspike) lwidth(medium) lcolor(gs10)) fileci2opts(recast(rspike) lwidth(thick) lcolor(gs10)) ///
legend(off) xtitle("Political News Consumption (TV)") ytitle("Effect of Woman Winning District") title("") scale(1.2) ///
xlabel(1 `" "Every once"  "in a while" "' 2 `" "Once"  "a week" "' 3 `" "Several times"  "a week" "' 4 "Daily") ///
note("Source: Mexico Panel Study, 2012. Notes: Thick lines indicate 90% confidence interval." ///
"Thin lines indicate 95% confidence interval.", span size(small)) 
graph export panel_polinfo_men.pdf, replace
* latex reg table (Table A3)
esttab using pol_info.tex, replace star(+ 0.10 * 0.05) compress se r2 label nobaselevels varwidth(25) mtitles("Women" "Men") ///
title("OLS Models of Post-Election Political Interest: Interactive Effect of Political Information"\label{tab:panelSurveyResultsInfo})

** descriptive stats for mass public analyses (Table A5)
eststo clear
estpost summ pol_int_W2 pol_int_W1 pol_talk_W2 woman_legwin jvm_w1 epn_w1 amlo_w1 age_group_indicator1 age_group_indicator2 age_group_indicator3 edr_indicator1 edr_indicator2 edr_indicator3 edr_indicator4 household_income mujer tv_news copartisan_s
esttab using descriptivestatsPanelSurvey.tex, replace cell("mean(fmt(%12.2f)) sd(fmt(%12.2f)) min(fmt(%12.0f)) max(fmt(%12.0f)) count(fmt(%12.0f))") nonumber nomtitle noobs label replace ///
title("Descriptive Statistics for 2012 Panel Data of Mass Public") 
